<%inherit file="/uxsino/base.html" />
<%block name="content" >

<script src="${STATIC_URL}uxsino/host.js"></script>

<div class="king-layout2-main mt15" style="width: 960px;">
	<form method="post" action="" class="form-horizontal">
		<input type="hidden" name="csrfmiddlewaretoken" value="${ csrftoken }"/>
		<div class="form-group clearfix ">
			<label class="col-sm-3 control-label bk-lh30 pt0">选择业务：</label>
			<div class="col-sm-9">
				<select name="bz_id" id="" class="form-control bk-valign-top">
					<option value="0">请选择业务</option>
					% if busses:
						% for k in busses.keys():
							<option value="${k}">${busses.get(k)}</option>
						% endfor
					% endif
				</select>
			</div>
		</div>
		<div class="form-group clearfix ">
			<label class="col-sm-3 control-label bk-lh30 pt0">输入内网IP：</label>
			<div class="col-sm-9">
				<input type="text" class="form-control bk-valign-top" name="ip"
					placeholder="提示信息">
			</div>
		</div>
		<div class="form-group clearfix">
			<div class="col-sm-9 col-sm-offset-3">
				<button type="submit" class="king-btn mr10  king-success">搜索</button>
				<button type="button" onclick="sync_host()" class="king-btn mr10  king-success">同步主机数据</button>
				<button type="button" onclick="exec_all()" class="king-btn mr10  king-success">下发脚本</button>
				<button type="button" onclick="sync_all()" class="king-btn mr10  king-success">同步执行状态</button>
			</div>
		</div>
	</form>
	<table class="table mb0 pr15 ranger-box ">
		<thead>
			<tr>
				<th style="width: 100px;">#</th>
				<th>IP</th>
				<th>Mem/Disk/CPU</th>
				<th>最后巡检时间</th>
				<th>大区</th>
				<th>模块</th>
				<th>云区域</th>
				<th>系统类型</th>
				<th>操作</th>
			</tr>

		</thead>
		<tbody>
			% if not datas:
			<td colspan="9" style="text-align: center; font-style: bold; font-size: 12px;">未找到数据</td>
			%else:
				% for itm in datas:
				<tr>
					<td >${itm.id}</td>
					<td >${itm.ip}</td>
					<td >${itm.mem_use if itm.mem_use else '--'}/${itm.disk_use if itm.disk_use else '--'}/${itm.cpu_use if itm.cpu_use else '--'}</td>
					<td >${itm.update_time}</td>
					<td >${itm.area}</td>
					<td >${itm.model}</td>
					<td >${itm.carea}</td>
					<td >${itm.os_type}</td>
					<td>
						<a title="脚本执行"  data-ip="${itm.id}" onclick="execS(${itm.id})" data-cloud="0" class="btn btn-xs btn-warning check-add">
                            <i class="glyphicon glyphicon-plus"></i>
                        </a>
                        <a title="查询结果" data-ip="${itm.id}" onclick="query(${itm.id})" data-cloud="0" class="btn btn-xs btn-success check">
                            <i class="glyphicon glyphicon-search"></i>
                        </a>
                    </td>
				</tr>
				% endfor
			% endif
		</tbody>
	</table>
</div>
<script>
	
	function sync_all(){
		$.ajax({
			url: "${SITE_URL}uxsino/syncAll/",
			data:{"csrfmiddlewaretoken": "${ csrftoken }"},
			type:"POST",
			dataType:"json",
			success:function(res){
				alert("提交成功")
			}
		});
	}
	function exec_all(){
		$.ajax({
			url: "${SITE_URL}uxsino/execAll/",
			data:{"csrfmiddlewaretoken": "${ csrftoken }"},
			type:"POST",
			dataType:"json",
			success:function(res){
				alert("提交成功")
			}
		});
	}
	

	function sync_host(){
		$.ajax({
			url: "${SITE_URL}uxsino/sync/",
			data:{"csrfmiddlewaretoken": "${ csrftoken }"},
			type:"POST",
			dataType:"json",
			success:function(res){
				alert("提交成功")
			}
		});
	}

	function execS(id){
		$.ajax({
			url: "${SITE_URL}uxsino/execS/",
			data:{"csrfmiddlewaretoken": "${ csrftoken }", "host_id": id},
			type:"POST",
			dataType:"json",
			success:function(res){
				alert("提交成功")
			}
		});
	}
	function query(id){
		$.ajax({
			url: "${SITE_URL}uxsino/query/",
			data:{"csrfmiddlewaretoken": "${ csrftoken }", "host_id": id},
			type:"POST",
			dataType:"json",
			success:function(res){
				location.reload();
			}
		});
	}
</script>
</%block>